package edu.zut.controller;

import edu.zut.pojo.User;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "JSPServlet", value = "/jspDemo")
public class JSPServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        HttpSession session = request.getSession();
        session.setAttribute("myName", "xueyin");
        User user = new User();
        user.setName("jack");
        user.setAge(20);
        session.setAttribute("user",user);
        ServletContext context = request.getServletContext();
        context.setAttribute("myName","xuexiaoyin");
        context.setAttribute("mySchool", "河南财经政法大学");
        request.setAttribute("myAge",20);
        request.setAttribute("user",user);
        request.getRequestDispatcher("/demo.jsp").forward(request,response);

        //重定向
//        response.sendRedirect(request.getContextPath() + "/demo.jsp");

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
